//
//  TLChengYuViewController.m
//  Books
//
//  Created by tao故乡的云 on 2017/3/17.
//  Copyright © 2017年 故乡的云. All rights reserved.
//

#import "TLChengYuViewController.h"
#import "TLHistoryController.h"
#import "TLReadPage.h"
#import "TLChengYu.h"
#import "TLCYLexiconController.h"
#import "TLLoveController.h"
//#import "TLBottomBar.h"
//#import "TLSearchView.h"


#define kRecommendCount 20 // 推荐阅读词条数

@interface TLChengYuViewController ()

@end

@implementation TLChengYuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
//    TLSearchView *search = [TLSearchView seachView];
//    search.frame = self.view.bounds;
//    search.backgroundColor = [UIColor grayColor];
//    
//    [self.view addSubview:search];
//    [TLBottomBar hidden];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)goToList:(id)sender {
    TLHistoryController *list = [[TLHistoryController alloc] init];
    list.title = @"历史阅读";
    [self.navigationController pushViewController:list animated:YES];
}

- (IBAction)goToRead:(id)sender {
    TLReadPage *read = [[TLReadPage alloc] init];

    // 随机数据
    NSMutableArray *items = [NSMutableArray array];
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *path = [cachePath stringByAppendingPathComponent:@"cyLexicon.plist"];
    NSArray *data = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; // 词库
    for (NSInteger i = 0; i < kRecommendCount; i++) {
            NSInteger a = arc4random_uniform((int)(data.count - 1));
            NSInteger b = arc4random_uniform((int)([data[a] count] - 1));
            [items addObject:data[a][b]];
    }
    read.items = items;
    read.currentItem = 0;
    [self.navigationController pushViewController:read animated:YES];
}

- (IBAction)goLexicon:(id)sender {
    TLCYLexiconController *list = [[TLCYLexiconController alloc] init];
    list.title = @"词库";
    [self.navigationController pushViewController:list animated:YES];
}

- (IBAction)goToLoveList:(id)sender {
    TLLoveController *list = [[TLLoveController alloc] init];
    list.title = @"收藏列表";
    [self.navigationController pushViewController:list animated:YES];
}
@end
